package entity

import (
	"time"
	"xr-game-server/core/constants/db"
	"xr-game-server/core/migrate"
	"xr-game-server/core/snowflake"
	"xr-game-server/core/syndb"
)

const (
	TbSysMail db.TbName = "sys_mails"
)

const (
	SysMailType db.TbCol = "type"
)

type SysMail struct {
	migrate.OneModel
	Type int32 `gorm:"comment:邮件类型"`
}

func initSysMail() {
	migrate.AutoMigrate(&SysMail{})
	syndb.RegQuickWithSmall(TbSysMail, SysMailType)
	syndb.RegQuickWithSmall(TbSysMail, db.CreatedAtName)
	syndb.RegQuickWithSmall(TbSysMail, db.UpdatedAtName)
}

func NewSysMail(typ int32) *SysMail {
	ret := &SysMail{}
	ret.ID = snowflake.GetId()
	ret.SetType(typ)
	ret.SetUpdateAt(time.Now())
	ret.SetCreateAt(time.Now())
	return ret
}

func (receiver *SysMail) SetCreateAt(val time.Time) {
	receiver.CreatedAt = val
	syndb.AddDataToQuickChan(TbSysMail, db.CreatedAtName, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
func (receiver *SysMail) SetUpdateAt(val time.Time) {
	receiver.UpdatedAt = val
	syndb.AddDataToQuickChan(TbSysMail, db.UpdatedAtName, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
func (receiver *SysMail) SetType(typ int32) {
	receiver.Type = typ
	syndb.AddDataToQuickChan(TbSysMail, SysMailType, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: typ,
	})
}
